<template>
	<view class="bg-white">
		<action-bar backTitle="返回" title="图表统计"></action-bar>
		<view>
			<view>
				<view class="text-lg padding-lr-xl margin-tb-sm">收入统计图</view>
				<view class="charts-box">
					<qiun-data-charts :chartData="summary.income" type="line" background="none"></qiun-data-charts>
				</view>
			</view>
			<view>
				<view class="text-lg padding-lr-xl margin-tb-sm">支出统计图</view>
				<view class="charts-box">
					<qiun-data-charts :chartData="summary.outcome" type="line" background="none"></qiun-data-charts>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bookId: null,
				summary: {
					income: {
						categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
						series: [{
							name: '收入(月)',
							data: []
						}]
					},
					outcome: {
						categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
						series: [{
							name: '支出(月)',
							data: []
						}]
					}
				}
			}
		},
		onLoad(option) {
			this.bookId = option.bookId
			this.querySummaryLineData()
		},
		methods: {
			querySummaryLineData() {
				this.$request({
					url: `/record/${this.bookId}/amount/summary`
				}).then(res => {
					if (res && res.data.code == 200) {
						this.summary.income.series[0].data = Object.values(res.data.list.income)
						this.summary.outcome.series[0].data = Object.values(res.data.list.outcome)
					}
				})
			}
		}
	}
</script>

<style>
</style>
